package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.service.ISkuStockService;
import com.spzx.product.vo.SkuLockVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品sku库存表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/skuStock")
public class SkuStockController extends BaseController {

    @Autowired
    private ISkuStockService skuStockService;


    /**
     * 检查与锁定库存，要求不能出现库存超卖
     * @param orderNo
     * @param skuLockVoList
     * @return
     */
    @InnerAuth
    @Operation(summary = "检查与锁定库存")
    @PostMapping("/checkAndLock/{orderNo}")
    public R<String> checkAndLock(@PathVariable String orderNo, @RequestBody List<SkuLockVo> skuLockVoList) {
        String stockErrorMsg = skuStockService.checkAndLock(orderNo, skuLockVoList);
        return R.ok(stockErrorMsg);
    }

}
